A=[1 0 -3 0 0 ; 1 8 -5 -2 0; 1 6 -6 0 -1; 3 7 -7 -1 -2]
format rational
A(1,:)=A(1,:)/A(1,1);
A(2,:)=A(2,:)-A(2,1)/A(1,1)*A(1,:);
A(3,:)=A(3,:)-A(3,1)/A(1,1)*A(1,:);
A(4,:)=A(4,:)-A(4,1)/A(1,1)*A(1,:);

A(2,:)=A(2,:)/A(2,2);
A(1,:)=A(1,:)-A(1,2)/A(2,2)*A(2,:);
A(3,:)=A(3,:)-A(3,2)/A(2,2)*A(2,:);
A(4,:)=A(4,:)-A(4,2)/A(2,2)*A(2,:);

A(3,:)=A(3,:)/A(3,3);
A(1,:)=A(1,:)-A(1,3)/A(3,3)*A(3,:);
A(2,:)=A(2,:)-A(2,3)/A(3,3)*A(3,:);
A(4,:)=A(4,:)-A(4,3)/A(3,3)*A(3,:);

A(4,:)=A(4,:)/A(4,4);
A(1,:)=A(1,:)-A(1,4)/A(4,4)*A(4,:);
A(2,:)=A(2,:)-A(2,4)/A(4,4)*A(4,:);
A(3,:)=A(3,:)-A(3,4)/A(4,4)*A(4,:);

A

